package com.adinnet.api.bootPage.controller;


import com.adinnet.api.bootPage.model.BootPage;
import com.adinnet.api.bootPage.service.BootPageService;
import com.adinnet.api.dict.model.Dict;
import com.adinnet.api.dict.service.DictService;
import com.adinnet.core.JsonResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 启动页表 前端控制器
 * </p>
 *
 * @author chenjia
 * @since 2021-03-03
 */
@RestController
@RequestMapping("/api/bootPage")
public class BootPageController {

    @Autowired
    private BootPageService bootPageService;

    @Autowired
    private DictService dictService;

    /**
     * 查询启动页
     *
     * @return
     */
    @GetMapping("getBootPage")
    public JsonResult getBootPage() {
        try {
            Dict dict = dictService.getOne(new QueryWrapper<Dict>().eq("dict_code", "BOOT_PAGE"));

            BootPage bootPage = bootPageService.getOne(new QueryWrapper<BootPage>().last("limit 1"));
            if (null == bootPage || (null != dict && 0 == dict.getSortNum())) {
                return JsonResult.ok("暂无启动页");
            }
            return JsonResult.ok().put("data", bootPage);
        } catch (Exception e) {
            return JsonResult.error("查询儿童个人信息失败!");
        }
    }

}
